using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using NHibernate.Data.Managers;
using NHibernate.Data.Models;
using NHibernate.Data.Base;

namespace NHibernate.Data.UnitTests
{
	[TestFixture]
    public partial class ReWineGrapeVarietyTests : UNuitTestBase
    {
        protected IReWineGrapeVarietyManager manager;
		
		public ReWineGrapeVarietyTests()
        {
            manager = managerFactory.GetReWineGrapeVarietyManager();
        }
		
		protected ReWineGrapeVariety CreateNewReWineGrapeVariety()
		{
			ReWineGrapeVariety entity = new ReWineGrapeVariety();
			
			entity.Wine = default(Int64);
			entity.GrapeVariety = default(Int64);
			
			entity.Percentage = default(Int16);
			
			return entity;
		}
		protected ReWineGrapeVariety GetFirstReWineGrapeVariety()
        {
            IList<ReWineGrapeVariety> entityList = manager.GetAll(1);
            if (entityList.Count == 0)
                Assert.Fail("All tables must have at least one row for unit tests to succeed.");
            return entityList[0];
        }
		
		[Test]
        public void Create()
        {
            try
            {
				ReWineGrapeVariety entity = CreateNewReWineGrapeVariety();
				
                object result = manager.Save(entity);

                Assert.IsNotNull(result);
            }
            catch(Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Read()
        {
            try
            {
                ReWineGrapeVariety entityA = CreateNewReWineGrapeVariety();
				manager.Save(entityA);

                ReWineGrapeVariety entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA, entityB);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
		[Test]
		public void Update()
        {
            try
            {
                ReWineGrapeVariety entityA = GetFirstReWineGrapeVariety();
				entityA.Percentage = default(Int16);
				
				manager.Update(entityA);

                ReWineGrapeVariety entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA.Percentage, entityB.Percentage);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Delete()
        {
            try
            {
                ReWineGrapeVariety entity = GetFirstReWineGrapeVariety();
				
                manager.Delete(entity);

                entity = manager.GetById(entity.Id);
                Assert.IsNull(entity);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
	}
}